﻿public class ICharacterAttr
{
    public ICharacterAttr(IAttrStrategy strategy, int lv, CharacterBaseAttr baseAttr)
    {
        mLv = lv;
        mBaseAttr = baseAttr;
        mStrategy = strategy;
        // 避免浪费性能，直接在构造函数中赋值
        mDmgDescValue = mStrategy.GetDmgDescValue(mLv);
        mCurrentHP = baseAttr.maxHP + mStrategy.GetExtraHPValue(mLv);
    }

    // protected string mIconSprite;
    // protected int mMaxHP;
    // protected float mMoveSpeed;
    // protected string mName;
    // protected float mCritRate; // 0 - 1暴击率 (敌人用)
    protected IAttrStrategy mStrategy;

    protected CharacterBaseAttr mBaseAttr;

    protected int mCurrentHP;

    public int currentHP { get { return mCurrentHP; } }

    // 暴击率 
    public int critValue { get { return mStrategy.GetCritDmg(mBaseAttr.critRate); } }
    protected int mLv; // 等级(战士用)
    protected int mDmgDescValue;

    // 用策略模式来管理下面几个属性
    // 额外增加的最大血量 减免的伤害 暴击率的暴击伤害加成


    public void TakeDamage(int damage)
    {
        // 伤害有一定的伤害减免
        damage -= mDmgDescValue;
        // 减免后的伤害不能小于5
        if (damage < 5) damage = 5;
        // 当前血量减少
        mCurrentHP -= damage;
    }

    public IAttrStrategy strategy { get { return mStrategy; } }
    public CharacterBaseAttr baseAttr { get { return mBaseAttr; } }
}